package com.ruoyi.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.ums.entity.MemberAddress;
import com.ruoyi.ums.mapper.MemberAddressMapper;
import com.ruoyi.ums.service.IMemberAddressService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 用户地址 服务实现类
 * </p>
 *
 * @author kenny
 * @since 2021-11-04
 */
@Service
public class MemberAddressServiceImpl extends ServiceImpl<MemberAddressMapper, MemberAddress> implements IMemberAddressService {


    public List<MemberAddress> selectAddressListByMemberId(Long memberId) {
        QueryWrapper<MemberAddress> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(MemberAddress::getMemberId, memberId);
        return baseMapper.selectList(wrapper);
    }

    public MemberAddress selectAddressDefaultByMemberId(Long memberId) {
        QueryWrapper<MemberAddress> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(MemberAddress::getIsDefault, 1)
                .eq(MemberAddress::getMemberId, memberId);
        return baseMapper.selectOne(wrapper);
    }

    public int insertAddress(MemberAddress address) {
        return baseMapper.insert(address);
    }

    public int updateAddress(MemberAddress address) {
        return baseMapper.updateById(address);
    }

    public int deleteAddressByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }
}
